package com.lizy

import org.junit.Test

class StrTest {

    /**
     * 习题1
     */
    @Test
    public void test1() {

        def str1 = "Hello" + "world";
        println("str1=" + str1);
        println("----------------------------------");
        def str2 = "11" + "34";
        println("str2=" + str2);
        println("----------------------------------");
        def str3 = "1" + "0";
        println("str3=" + str3);
    }

    /**
     * 习题2
     */
    @Test
    public void test2() {
        println('"Hello".length() : ' + "Hello".length());
        println('"".length() : ' + "".length());
    }

    /**
     * 习题3
     */
    @Test
        public void test3() {
        def str = "Hello world";
        println('str.indexOf("or") : ' + str.indexOf("or"));
        println('str.indexOf("Or") : ' + str.indexOf("Or"));
        println('str.lastIndexOf("o") : ' + str.lastIndexOf("o"));
        println('str.lastIndexOf("or") : ' + str.lastIndexOf("or"));
    }


    /**
     * 习题4
     */
    @Test
    public void test4() {
        def str = "Groovy, Groovy, Groovy";
        println('str.length : ' + str.length());
        println('str.indexOf("o") : ' + str.indexOf("o"));
        println('str.lastIndexOf("o") : ' + str.lastIndexOf("o"));
        println('str.indexOf("o",5) : ' + str.indexOf("o",5));
        println('str.lastIndexOf("o",5) : ' + str.lastIndexOf("o",5));
        println('str.indexOf("ov",str.length()-10) : ' + str.indexOf("ov",str.length()-10));
        println('str.lastIndexOf("ov",str.length()-4) : ' + str.lastIndexOf("ov",str.length()-4));
        println('str.indexOf("o",str.indexOf("ro")) : ' +  str.indexOf("o",str.indexOf("ro")));
    }

    @Test
    public void test5() {
        def str = "Groovy programming";
        println('str.length() : ' + str.length());
        println('str.substring(7,14) : ' + str.substring(7,14));
        println('str.substring(1,str.length()-1) : ' + str.substring(1,str.length()-1));
        println('str.endsWith("ming") : ' + str.endsWith("ming"));
    }

    @Test
    public void test() {
        Student student = new Student("xiaohong");
        println(student.name);
        student.age = 111;
        println(student.age);
    }

    @Test
    public void test6() {
        def maps = [
                [
                        k1:"v1",
                        k2:"v2"
                ]
        ]
        println maps.collect {it.k1}
    }

    class Student{
        def name;
    }

    @Test
    void test7() {
        println(Strings.isBl)
    }
}
